//该文件专门用于创建整个应用的路由器
import VueRouter from "vue-router"
//引入组件
import Home from '../pages/Home'
import About from '../pages/About'
import News from '../pages/News'
import Message from '../pages/Message'
import Detail from '../pages/Detail'
import router from "26.src_路由的基本使用/router"

//创建并导出一个路由器
export default new VueRouter({
  routes:[
    {
      name:'guanyu',
      path:'/about',
      component:About,
      meta:{title:'关于'}
    },
    {
      name:'zhuye',
      path:'/home',
      component:Home,
      meta:{title:'主页'},
      children:[
        {
          name:'xinwen',
          path:'news',
          component:News,
          meta:{isAuth:true,title:'新闻'}
        },
        {
          name:'xiaoxi',
          path:'message',
          component:Message,
          meta:{isAuth:true,title:'消息'},
          children:[
            {
              name:'xiangqing',
              // path:'detail/:id/:title', //使用占位符声明接收params参数
              component:Detail,
              meta:{isAuth:true,title:'详情'},
              //为真，把该路由组件收到的所有的params参数，以props的形式传给Detail组件
              // props:true,
              //props的第三种写法，值为函数
              props($route){
                return{
                  id:$route.query.id,
                  title:$route.query.title
                }
              }

            },
            
          ]
        }
        
      ]
    }
  ]
})

//全局前置路由守卫-----初始化的时候，每次路由切换之前被调用
router.beforeEach((to,from,next)=>{
  console.log(to,from);

})